package com.microsoft.tag.admin.demo.kingbase8.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.microsoft.tag.admin.demo.kingbase8.entity.KingBase8User;
import com.microsoft.tag.admin.demo.kingbase8.service.KingBase8UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 软件著作权:王艳明
 * 系统名称:SpringBoot后台管理系统
 *
 * @author WangYanming
 * @ClassName 类:KingBase8UserController.java
 * @Description 功能描述:controller
 * @Version 1.0
 * @date 2025-10-16 上午 09:29
 */
@RestController
@RequestMapping(value = "/admin/demo/kingbase8/user")
public class KingBase8UserController {

    @Autowired
    private KingBase8UserService userService;

    // 新增用户
    @PostMapping
    public boolean save(@RequestBody KingBase8User user) {
        return userService.save(user);
    }

    // 更新用户
    @PutMapping
    public boolean update(@RequestBody KingBase8User user) {
        return userService.updateById(user);
    }

    // 删除用户
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Long id) {
        return userService.removeById(id);
    }

    // 获取单个用户
    @GetMapping("/{id}")
    public KingBase8User getById(@PathVariable Long id) {
        return userService.getById(id);
    }

    // 获取所有用户
    @GetMapping
    public List<KingBase8User> getAll() {
        return userService.list();
    }

    // 分页查询
    @GetMapping("/page")
    public IPage<KingBase8User> getPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        IPage<KingBase8User> page = new Page<>(pageNum, pageSize);
        return userService.page(page);
    }
}
